package com.yiwyn.utils;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;

import java.util.concurrent.Callable;
import java.util.function.Supplier;

@Slf4j
public class WrapUtil {

    public static void trace(Supplier<String> field, Runnable runnable) {
        String traceId = field.get();
        MDC.put("traceId", traceId);
        runnable.run();
        MDC.clear();
    }


    public static <T, R> R wrap(Callable<R> callable) throws Exception {
        log.info("执行callable方法");
        return callable.call();
    }

}
